/*
 * @Author       : NaN 353362604@qq.com
 * @Date         : 2023-05-30 10:52:35
 * @LastEditTime : 2023-06-07 08:58:00
 * @LastEditors  : NaN 353362604@qq.com
 * @FilePath     : \AdminStration\src\Common\Router\MenuNav\FirstLevel\MaterialType.jsx
 * @Description  :
 */

import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton } from '../Common/options'
import { MaterialTypeTree } from '../Common/Conversion'

export const MaterialType = async ({ url, OptionsEvent, Permission }) => {
    const parentUuid = await MaterialTypeTree()
    let data = {
        pageSize: 10,
        params: { pageIndex: 1 },
        hideInSearch: true,
        get: API_LIST()[`get${url}Tree`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            Permission?.findIndex(v => v.uuid === 'd15c214c-e28d-434f-b25a-47347b972471') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} url={url} type="primary" icon="add" title="新增材料类别" />
            ),
        ],
        columns: [
            commonTableList.uuid,
            { ...commonTableList.tableName, title: '材料类别名称' },
            {
                ...commonTableList.parentUuid,
                fieldProps: {
                    fieldNames: { label: 'tableName', value: 'uuid' },
                    options: parentUuid,
                },
            },
            {
                dataIndex: 'level',
                title: '层级',
                valueType: 'inputNumber',
                rules: true,
                width: 50,
            },
            { ...commonTableList.sortId, rules: true },
            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 200,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    return [
                        Permission.findIndex(v => v.uuid === 'b8978dbf-2827-4c5c-82c3-e6b0d74eb7c8') !== -1 && (
                            <ModDataButton
                                OptionsEvent={OptionsEvent}
                                key="modify"
                                title="修改"
                                url={url}
                                data={record}
                            />
                        ),
                        Permission.findIndex(v => v.uuid === 'c4f41e1a-0c16-460a-a259-b733c223587e') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
